<template>
    <div>
      <el-dialog
        :title="dialogtitle"
        width="800px"
        class="icon-dialog"
        :visible.sync="show"
        :before-close="closeForm"
        append-to-body
        @open="open" >
        <el-form
          ref="form"
          :size="size"
          :model="form"
          :rules="rules"
          :label-width="$store.getters.device !== 'mobile'?'16%':'90px'"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item label="企业名称"  >
                <el-input v-model="form.title" auto-complete="off" clearable  disabled />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="联系人" >
                <el-input v-model="form.contacts" auto-complete="off" clearable  disabled />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="电话" >
                <el-input v-model="form.mobile" auto-complete="off" clearable  disabled />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="营业执照" >
                <el-image
                    style="width: 100px; height: 100px"
                    :src="form.business"
                    fit="fill" >
                </el-image>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="审核状态" >
                <el-radio-group v-model="form.state" @change="onClickState" >
                <el-radio :label="0" name="state" >未审核</el-radio>
                <el-radio :label="1" name="state" >通过</el-radio>
                <el-radio :label="2" name="state" >未通过</el-radio>
              </el-radio-group>
              </el-form-item>
            </el-col>
         </el-row>

         <el-row>
            <el-col :span="24">
              <el-form-item label="审核状态" >
                <el-input type="textarea" v-model="form.state_msg"></el-input>
              </el-form-item>
            </el-col>
         </el-row>


        </el-form>
        <div slot="footer" class="dialog-footer" v-if="form.state == 0">
          <el-button :loading="loading" type="primary" @click="submit">
            <span v-if="!loading">保 存</span>
            <span v-else>提 交 中...</span>
          </el-button>
          <el-button @click="closeForm">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  import ImagesUpload from '@/components/common/ImagesUpload.vue'
  export default {
    name: 'Servicecategoryupdate',
    components: {
      Treeselect,
      ImagesUpload
    },
    props: {
      show: {
        type: Boolean,
        default: false
      },
      opentype: {
        type: String,
        default: 'add'
      },
      size: {
        type: String,
        default: 'small'
      },
      info: {
        type: Object
      }
    },
    data() {
      return {
        dialogtitle: '',
        goodsdeliverymodearray: [],
        remarkarray:[],
        form: {},
        pids: [],
        ptypearray: [],
        loading: false,
        rules: {
          title: [{
            required: true,
            message: '名称不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    watch: {
      show(val) {
        if (val) {
        }
      }
    },
    methods: {
        onClickState(){
            console.log(this.form.state)
            if(this.form.state == 2){

            }

        },
      open() {
        if (this.opentype == 'update') {
            if(this.info.state == 0){
                this.dialogtitle = '审核'
            }else{
                this.dialogtitle = '查看'
            }
          
          this.form = this.info
          console.log(this.info.state)
        }
  

      },
      submit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            this.$api.post('/enter/update', this.form).then(res => {
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.$emit('refesh_list')
              this.closeForm()
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      normalizer(data) {
        if (data.children && !data.children.length) {
          delete data.children
        }
        return {
          id: data.val,
          label: data.key,
          children: data.children
        }
      },
      closeForm() {
        this.$emit('update:show', false)
        this.loading = false
        if (this.$refs['form'] !== undefined) {
          this.$refs['form'].resetFields()
        }
      }
    }
  }
  </script>
  